package hos.http;

import java.io.File;
import java.io.Serializable;

/**
 * <p>Title: HttpFile </p>
 * <p>Description: 上传附件实体 </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2023-02-24 13:06
 */
public class HttpFile implements Serializable {
    private String key;
    private String fileName;
    private String filePath;

    public HttpFile(String name, String filePath) {
        this(name, null, filePath);
    }

    public HttpFile(String name, String fileName, String filePath) {
        this.key = name;
        if (fileName == null) {
            this.fileName = HttpStringUtils.substringAfterLast(filePath, '/', "");
        } else {
            this.fileName = fileName;
        }
        this.filePath = filePath;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public File getFile() {
        return new File(filePath);
    }

    public String toJson() {
        return "{\"name\":\"" + getKey() + "\"," +
                "\"fileName\":\"" + getFileName() + "\"," +
                "\"filePath\":\"" + getFilePath() + "\"}";
    }

    @Override
    public String toString() {
        return "HttpFile{" +
                "name='" + key + '\'' +
                ", fileName='" + fileName + '\'' +
                ", filePath='" + filePath + '\'' +
                '}';
    }
}
